/*
 * @lc app=leetcode.cn id=14 lang=javascript
 *
 * [14] 最长公共前缀
 */

// @lc code=start
/**
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function (strs) {
    let str = ''
    let len = Number.MAX_SAFE_INTEGER  // 最大整数
    strs.forEach(item => {
        if (item.length < len) len = item.length
    })
    for (let i = 0; i < len; i++) {
        let sameStr = strs[0][i]
        for (let j = 1; j < strs.length; j++) {
            if (strs[j][i] != sameStr) {
                return str
            }
        }
        str = str + sameStr
    }
    return str
};
// @lc code=end
// @after-stub-for-debug-begin
module.exports = longestCommonPrefix;
// @after-stub-for-debug-end